package com.finance.system.service;

import com.finance.system.bean.pojo.UserRoleRel;
import com.finance.system.dao.UserRoleMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * Created by CBWL on 2017/3/9.
 */
@Service
public class UserRoleService implements IUserRoleService{
    @Resource
    private UserRoleMapper userRoleMapper;

    /**
     * 根据id查询用户角色关系list
     * @param id
     * @return
     */
    @Override
    public UserRoleRel getById(Long id) {
        return this.userRoleMapper.getById(id);
    }

    /**
     * 根据id查询用户角色关系list
     * @param roleId
     * @return
     */
    @Override
    public List<UserRoleRel> getByRoleId(Long roleId) {
        return this.userRoleMapper.getByRoleId(roleId);
    }

    /**
     * 根据工号查询用户角色关系list
     * @param userCode
     * @return
     */
    @Override
    public List<UserRoleRel> listByUserCode(String userCode){
        return this.userRoleMapper.listByUserCode(userCode);
    }

    /**
     * 新增用户
     * @param userRoleRel
     * @return
     */
    @Override

    public boolean add(UserRoleRel userRoleRel) {
        return userRoleMapper.add(userRoleRel)==1;
    }

    /**
     * 更新用户角色关系
     * @param userRoleRel
     * @return
     */
    @Override

    public boolean update(UserRoleRel userRoleRel) {
        return userRoleMapper.update(userRoleRel)==1;
    }

    /**
     * 删除用户
     * @param id
     * @return
     */
    @Override
    public boolean delete(Long id) {
        return userRoleMapper.delete(id)==1;
    }

    /**
     * 根据工号删除用户角色关系
     * @param code
     * @return
     */
    @Override
    public boolean deleteByCode(String code){
        return userRoleMapper.deleteByCode(code)>0;
    }

    @Override
    public List<UserRoleRel> queryNo(String code){
        return userRoleMapper.queryNo(code);
    }
}
